  //验证码
  //随机生成验证码
  function fun() {
      let usernumber = "0123456789abcdefghijklmnopqrstuvwxvzABCDEFGHIJKLMNOPQRSTUVWXYZ";
      let passnumber = "0123456789abdefABCDEF";
      let num = "";
      let pass = "#";
      //随机字体
      for (let i = 0; i < 4; i++) {
          let n = parseInt(Math.random() * usernumber.length);
          num += usernumber[n];
      }
      //随机颜色
      for (let j = 0; j < 6; j++) {
          let n = Math.floor(Math.random() * passnumber.length);
          pass += passnumber[n];
      }
      $("#yanzhengma").val(num).css("color", pass);
  }
  fun();
  $("#newbtn").click(() => {
      fun();
  })



  //点击button提交
  $("#btn").click(function() {
          if (!$("#chick").prop("checked")) {
              alert("请点击确认用户协议");
              return;
          }
          if (num1 === true && num2 === true && num3 === true && num4 === true) {
              let username = $("#newname").val();
              let userpass = $("#uspass").val();
              $.ajax({
                  method: "get",
                  url: "http://192.168.50.142:81/adduser",
                  data: {
                      name: username,
                      pass: userpass
                  },
                  success: function(data) {
                      if (data === "success") {
                          alert("注册成功");
                          location.href = "http://192.168.50.142/MIDO/denglu.html";
                      }
                      if (data === "exist") {
                          alert("您注册的用户名已经存在");
                          fun();
                      }
                  }
              })
          } else {
              alert("请完善注册信息");
          }

      })
      //============================================
  let num1 = false;
  $("#newname").blur(function() {
      let newname = $("#newname").val();
      if (newname === "" || newname === "请输入用户名") {
          $(".pone").css("display", "block");
          num1 = false;
      } else {
          $(".pone").css("display", "none");
          num1 = true;
      }
  });

  //===========================判断密码是否为空
  let num2 = false;
  $("#uspass").blur(function() {
          let newname = $("#uspass").val();
          if (newname === "") {
              $(".ptwo").css("display", "block");
              num2 = false;
          } else {
              $(".ptwo").css("display", "none");
          }
          num2 = true;
      })
      //===========================判断两次密码是否一致
  let num3 = false;
  $("#newuspass").blur(function() {
          let oldname = $("#uspass").val();
          let newname = $("#newuspass").val();
          if (newname === "") {
              $(".pthree").css("display", "block");
              num3 = false;
          } else {
              $(".pthree").css("display", "none");
              if (oldname !== newname) {
                  alert("两次密码不一致");
                  num3 = false;
              } else {
                  num3 = true;
              }
          }
      })
      //===========================判断验证码是否为空
  let num4 = false;
  $("#verification").blur(function() {
      let oldname = $("#yanzhengma").val();
      let newname = $("#verification").val();
      if (newname === "") {
          $(".pfore").css("display", "block");
          num4 = false;
      } else {
          $(".pfore").css("display", "none");
          if (oldname !== newname) {
              alert("两次验证码不一致");
              num4 = false;
          } else {
              num4 = true;
          }
      }
  })